package com.mail.server.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.api.OmsOrderReturnReasonApi;
import com.mail.model.db.OmsOrderReturnReason;
import com.mail.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service
public class OmsOrderReturnReasonService {

    @DubboReference
    private OmsOrderReturnReasonApi orderReturnReasonApi;

    //分页查询退货原因
    public PageResult list(Integer pageNum, Integer pageSize) {
        Page page = orderReturnReasonApi.queryByPage(pageNum, pageSize);
        return new PageResult(page.getCurrent(), page.getSize(), page.getTotal(), page.getRecords());
    }

    //根据id，获取单个退货原因详情信息
    public OmsOrderReturnReason select(Long id) {
        return orderReturnReasonApi.findById(id);
    }

    //修改退货原因
    public Integer updateReturnReason(Long id, OmsOrderReturnReason reason) {
        return orderReturnReasonApi.updateReturnReason(reason);
    }

    //修改退货原因启用状态
    public Integer updateStatus(Long id, Integer status) {
        OmsOrderReturnReason orderReturnReason = new OmsOrderReturnReason();
        orderReturnReason.setId(id);
        orderReturnReason.setStatus(status);
        return orderReturnReasonApi.updateReturnReason(orderReturnReason);
    }

    //批量删除退货原因
    public Integer delete(List<Long> ids) {
        return orderReturnReasonApi.deleteByIds(ids);
    }

    //添加退货原因
    public Integer create(OmsOrderReturnReason reason) {
        reason.setCreateTime(LocalDateTime.now());
        return orderReturnReasonApi.save(reason);
    }
}
